// 显示无模式对话框
function ShowDialog(url, width, height) {
   var arr=showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:auto;status:no");
   return arr;
}
function setimg(obj){
   obj.picchk.style.height='';
   obj.picchk.style.width='';
   obj.picchk.style.display='block';
   obj.picchk.src=obj.uploadfile.value;
}
//等比例缩小图片显示
function scalepic(w,h,pic){
   var xw,xh;
   xw=pic.width/w;
   xh=pic.height/h;
   if(xw==0)setTimeout(scalepic(w,h),2000);
   h1=pic.height/xw;
   w1=pic.width/xh;
   if(xw>xh){
      if(pic.width>w){
         pic.style.width=w;
         pic.style.height=h1;
      }
   }
   else{
        if(pic.height>h){
           pic.style.height=h;
           pic.style.width=w1;
        }
   }
}
function URLParams (ParamName){
   // 取通过URL传过来的参数 (格式如 ?Param1=Value1&Param2=Value2)

   var URLParams = new Object();
   var aParams = document.location.search.substr(1).split('&');
   for(i=0; i < aParams.length; i++){
       var aParam = aParams[i].split('=');
       URLParams[aParam[0]] = aParam[1];
   }
   return URLParams[ParamName];
}
//获得选中的值
function getCheckboxItem(obj){
   var allSel="";
   if(obj.value) return obj.value;
   for(i=0;i<obj.length;i++){
       if(obj[i].checked){
          if(allSel=="")allSel=obj[i].value;
          else allSel=allSel+","+obj[i].value;
       }
   }
   return allSel;
}
function checkorno(obj1,obj2){
   if(obj1.checked){
      if(!obj2.length){
          obj2.checked=true;
          return;
      }
      for(i=0;i<obj2.length;i++){
          obj2[i].checked=true;
      }
   } else {
      if(!obj2.length){
          obj2.checked=false;
          return;
      }
      for(i=0;i<obj2.length;i++){
          obj2[i].checked=false;
      }
   }
}
function selAll(obj){
   if(!obj.length){
       obj.checked=true;
       return;
   }
   for(i=0;i<obj.length;i++){
       if(!obj[i].checked)obj[i].checked=true;
   }
}
function noSelAll(obj){
   if(obj.value){
      if(obj.checked)obj.checked=false;
      else obj.checked=true;
   }
   for(i=0;i<obj.length;i++){
       if(obj[i].checked)obj[i].checked=false;
       else obj[i].checked=true;
   }
}
function selectBoy(obj){
   var obj1=obj.cateids;
   var obj2=obj.catelevel;
   var catelevel=0;
   if(!obj1.value){
         for(i=0;i<obj1.length;i++){
             if(obj1[i].checked){
                catelevel=obj2[i].value;
             } else {
                   if(obj2[i].value>catelevel && catelevel!=0)obj1[i].checked=true;
                   else catelevel=0;
             }
         }
   }
}
function subform(form,obj,act,msg){
   var qstr=getCheckboxItem(obj);
   if(qstr=="")alert("你没选中任何内容！");
   else{
        if(msg!='' && !confirm(msg))return false;
        form.action=act;
        form.selids.value=qstr;
        form.submit();
   }
}
function subforms(form,act,msg){
   if(msg!='' && !confirm(msg))return false;
   form.action=act;
   form.submit();
}
function move(form,obj,target,act){
   var qstr=getCheckboxItem(obj);
   if(String(parseInt(target)) != target){
      alert('不能移动到有子分类的分类中！');
      return false;
   }
   if(qstr=="") alert("你没选中任何内容！");
   else{
        form.action=act;
        form.selids.value=qstr;
        form.submit();
   }
}
function addarttospl(obj,specialid,referer){
   var qstr=getCheckboxItem(obj.articleids);
   if(specialid==''){
      alert("请先选择专题！");
      return;
   }
   if(qstr=="") alert("你没选中任何内容！");
   else{
        obj.action="?file=deal&specialid="+specialid+"&action=addarttospl&referer="+referer;
        obj.selids.value=qstr;
        obj.submit();
   }
}

function confirmform(form,message){
   if(confirm(message))form.submit();
}

function menuChange(menu){
   if(menu.style.display=="none"){
      menu.style.display="block";
   } else {
      menu.style.display="none";
   }
}

function set_display(id,val){
   id.style.display=val;
}
function set_value(id, val){
	$('#'+id).val(val);
}
function get_tags(id, title, content){
	var tv = $('#'+title).val();
	var cv = $('#'+content).val();
	if(tv == '' && cv == '') return false;
	$.get('api/relatekw.php?title='+tv+'&content='+cv+'&id='+Math.random()*5, function(data){
		if(data !='') $('#'+id).val(data);
	});
}

//检查字符串是否在给定的数组中,返回位数
function inarray(obj, arr) {
if(typeof obj == 'string') {
   for(var i in arr) {
    if(arr[i] == obj) {
      return i;
    }
   }
}
return false;
}